package com.infoland.afanmall.model.youXuan.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.CONST;
import com.infoland.afanmall.base.util.CacheKit;
import com.infoland.afanmall.base.util.GlideKit;
import com.infoland.afanmall.base.util.LogKit;
import com.infoland.afanmall.base.util.StatusBarKit;
import com.infoland.afanmall.base.util.ToolsKit;
import com.infoland.afanmall.base.util.UserKit;
import com.infoland.afanmall.base.util.banner.HolderCreator;
import com.infoland.afanmall.base.util.okhttp.ErrorInternet;
import com.infoland.afanmall.base.util.okhttp.OkHttpKit;
import com.infoland.afanmall.base.view.webview.WebViewActivity;
import com.infoland.afanmall.model.fuPin.activity.FpCunInfoActivity;
import com.infoland.afanmall.model.my.activity.KeFuActivity;
import com.infoland.afanmall.model.order.activity.OrderDownActivity;
import com.infoland.afanmall.model.shopCart.activity.ShopCartActivity;
import com.infoland.afanmall.model.youXuan.entity.GoodInfoEntity;
import com.infoland.afanmall.model.youXuan.entity.GoodInfoGuiGeEntity;
import com.infoland.afanmall.model.youXuan.entity.PingJiaOneEntity;
import com.vondear.rxtools.RxDeviceTool;
import com.wyj.floatlayout.FlowLayout;
import com.wyj.floatlayout.TagAdapter;
import com.wyj.floatlayout.TagFlowLayout;
import com.wyj.floatlayout.TagView;
import com.youth.banner.transformer.AccordionTransformer;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodInfoActivity extends AppCompatActivity {
    @BindView(R.id.good_info_banner)
    ConvenientBanner goodInfoBanner;
    @BindView(R.id.info_xian_jia)
    TextView infoXianJia;
    @BindView(R.id.info_yuan_jia)
    TextView infoYuanJia;
    @BindView(R.id.price_text_layout)
    LinearLayout priceTextLayout;
    @BindView(R.id.info_good_title)
    AppCompatTextView infoGoodTitle;
    @BindView(R.id.info_good_content)
    AppCompatTextView infoGoodContent;
    @BindView(R.id.info_fui_ge_yi_xuan)
    TextView infoFuiGeYiXuan;
    @BindView(R.id.info_fui_ge_name)
    TextView infoFuiGeName;
    @BindView(R.id.info_fui_ge_dian_dian_dian)
    LinearLayout infoFuiGeDianDianDian;
    @BindView(R.id.ys_gui_ge)
    LinearLayout ysGuiGe;
    @BindView(R.id.info_fu_pin_img)
    ImageView infoFuPinImg;
    @BindView(R.id.info_fu_pin_cun_zi)
    TextView infoFuPinCunZi;
    @BindView(R.id.info_fu_pin_content)
    TextView infoFuPinContent;
    @BindView(R.id.info_fu_pin_xaing_qing)
    LinearLayout infoFuPinXaingQing;
    @BindView(R.id.info_pin_kun)
    LinearLayout infoPinKun;
    @BindView(R.id.info_su_yuan)
    LinearLayout infoSuYuan;
    @BindView(R.id.info_recycle)
    RecyclerView infoRecycle;
    @BindView(R.id.info_wei_xin_img)
    AppCompatImageView infoWeiXinImg;
    @BindView(R.id.info_wei_xin_txt1)
    AppCompatTextView infoWeiXinTxt1;
    @BindView(R.id.info_wei_xin_txt2)
    AppCompatTextView infoWeiXinTxt2;
    @BindView(R.id.info_wei_xin_txt3)
    AppCompatTextView infoWeiXinTxt3;
    @BindView(R.id.info_wei_xin_copy)
    AppCompatTextView infoWeiXinCopy;
    @BindView(R.id.goog_info_bottom_shouc)
    LinearLayout googInfoBottomShouc;
    @BindView(R.id.goog_info_bottom_cart)
    LinearLayout googInfoBottomCart;
    @BindView(R.id.goog_info_bottom_jia)
    LinearLayout googInfoBottomJia;
    @BindView(R.id.goog_info_bottom_by)
    LinearLayout googInfoBottomBy;
    @BindView(R.id.goog_info_bottom_xin)
    AppCompatImageView googInfoBottomXin;
    @BindView(R.id.lable_flow_layout)
    TagFlowLayout lableFlowLayout;
    @BindView(R.id.lable_ll)
    LinearLayout lableLl;
    //
    int id;
    private GoodInfoGuiGeEntity goodInfoGuiGeEntity = null;//当前规格信息
    @BindView(R.id.pj_recycler)
    RecyclerView pjRecycler;
    @BindView(R.id.pj_number)
    TextView pjNumber;
    @BindView(R.id.pj_du)
    TextView pjDu;
    @BindView(R.id.pj_all)
    LinearLayout pjAll;
    @BindView(R.id.ping_jia)
    LinearLayout pingJia;
    @BindView(R.id.look_pj_all)
    LinearLayout lookPjAll;

    private int getLayout() {
        return R.layout.good_info_activity;
    }

    private void initData() {
        getGoodDetails(id);
        getPingJia(id);
    }

    //请求评价信息
    private void getPingJia(int id) {
        JSONObject para = new JSONObject();
        para.put("pageNumber", 1);//  是 int 页数
        para.put("pageSize", 5);//         是 int 页大小
        para.put("goodsId", id);//是 int 商品id
        new OkHttpKit().send(
                response200 -> {
                    PingJiaOneEntity pingJiaOneEntity = JSONObject.parseObject(response200, PingJiaOneEntity.class);
                    if (pingJiaOneEntity.getTotalRow() == 0) {
                        pingJia.setVisibility(View.GONE);
                    } else {
                        pingJia.setVisibility(View.VISIBLE);
                        setPingJia(pingJiaOneEntity.getList(), pingJiaOneEntity.getTotalRow());
                    }
                    LogKit.E("response200 ---->   ", "  " + response200);
                },
                success401 -> {
                    LogKit.E("error ---->   ", "  " + success401);
                },
                error -> {
                    ToastUtils.showShort("操作失败");
                }
        ).post(CONST.SELECT_PING_JIA_GOODS, para, this);
    }

    //设置评价信息
    private void setPingJia(List<PingJiaOneEntity.ListBean> list, int size) {
        String number = "商品评价(" + size + ")";//
        pjNumber.setText(number);
        pjRecycler.setLayoutManager(new LinearLayoutManager(this));
        pjRecycler.setAdapter(new BaseQuickAdapter<PingJiaOneEntity.ListBean, BaseViewHolder>
                (R.layout.good_info_item_ping_jia, list) {
            @Override
            protected void convert(BaseViewHolder helper, PingJiaOneEntity.ListBean item) {
                ToolsKit.setImgActivity(GoodInfoActivity.this, item.getUser_head_img_url(), helper.getView(R.id.pj_header));
                ToolsKit.setText(helper.getView(R.id.pj_name), item.getUser_name());
                ToolsKit.setText(helper.getView(R.id.pj_content), item.getEvaluate_context());
                ToolsKit.setStars(item.getEvaluate_star(), helper.getView(R.id.star1),
                        helper.getView(R.id.star2), helper.getView(R.id.star3),
                        helper.getView(R.id.star4), helper.getView(R.id.star5));
                if (item.getImages().size() == 0) {
                    helper.getView(R.id.pj_img1).setVisibility(View.GONE);
                    helper.getView(R.id.pj_img2).setVisibility(View.GONE);
                } else if (item.getImages().size() >= 1 && item.getImages().size() < 2) {
                    helper.getView(R.id.pj_img2).setVisibility(View.GONE);
                    ToolsKit.setImgActivity(GoodInfoActivity.this, item.getImages().get(0).getF_url(), helper.getView(R.id.pj_img1));
                } else if (item.getImages().size() >= 2) {
                    ToolsKit.setImgActivity(GoodInfoActivity.this, item.getImages().get(0).getF_url(), helper.getView(R.id.pj_img1));
                    ToolsKit.setImgActivity(GoodInfoActivity.this, item.getImages().get(1).getF_url(), helper.getView(R.id.pj_img2));
                    return;
                }
            }
        });
    }

    //商品详情
    private void getGoodDetails(int id) {
        JSONObject para = new JSONObject();
        para.put("id", id);
        JSONObject params = new JSONObject();
        params.put("pageNumber", 1);
        params.put("pageSize", 10);
        new OkHttpKit().send(
                response200 -> {
                    LogKit.E("商品详情 ---->   ", "  " + response200);
                    GoodInfoEntity goodInfoEntity = JSONObject.parseObject(response200, GoodInfoEntity.class);
                    if (goodInfoEntity != null) {
                        updateUI(goodInfoEntity);
                    }
                },
                success401 -> {
                    LogKit.E("success401 ---->   ", "  " + success401);
                },
                error -> {
                    LogKit.E("error ---->   ", "  " + error);
                }
        ).post(CONST.GOOD_INFO + UserKit.getAccessToken(), para, this);
    }

    //修改界面信息
    private void updateUI(GoodInfoEntity goodInfoEntity) {
        setDefaultGoodStatus(goodInfoEntity.getGoodsPrice(), goodInfoEntity.getF_url(), goodInfoEntity.getG_name());
        setGuiGe(goodInfoEntity);
        addLinster(goodInfoEntity);
        setBanner(goodInfoEntity);
        setContent(goodInfoEntity);
        setLable(goodInfoEntity);
        setFpCun(goodInfoEntity);
        //设置 溯源信息
        if (goodInfoEntity.getG_trace_code() == null) {
            infoSuYuan.setVisibility(View.GONE);
        } else {
            infoSuYuan.setVisibility(View.VISIBLE);
        }

        setImages(goodInfoEntity);// 设置图片集合
        setWeiXin();
        ToolsKit.setText(pjDu, goodInfoEntity.getNice_rate() + "", "%");

    }

    //设置默认规格
    private void setDefaultGoodStatus(GoodInfoEntity.GoodsPriceBean goodsPrice, String f_url, String name) {
        if (goodsPrice != null) {
            goodInfoGuiGeEntity = new GoodInfoGuiGeEntity();
            goodInfoGuiGeEntity.setNow_count(1);//数量
            goodInfoGuiGeEntity.setNow_good_id(goodsPrice.getGoods_id() + "");//商品ID
            goodInfoGuiGeEntity.setNow_gui_ge(goodsPrice.getSpec());//规格
            goodInfoGuiGeEntity.setNow_gui_ge_name(goodsPrice.getSpec_name());//规格名
            goodInfoGuiGeEntity.setNow_img_url(f_url);//当前img
            goodInfoGuiGeEntity.setNow_name(name);//当前name
            goodInfoGuiGeEntity.setNow_origin_price(goodsPrice.getGoods_origin_price());//原价
            goodInfoGuiGeEntity.setNow_price(goodsPrice.getGoods_price());//现价
            goodInfoGuiGeEntity.setNow_price_id(goodsPrice.getId());//价格Bean id
            goodInfoGuiGeEntity.setNow_type(CONST.OPEN_SELECT_GUI_GE);//现在Type
        } else {
            goodInfoGuiGeEntity = null;
        }
    }

    //设置扶贫村
    private void setFpCun(GoodInfoEntity goodInfoEntity) {
        GoodInfoEntity.FupincunBean fupincun = goodInfoEntity.getFupincun();
        if (fupincun != null) {
            infoPinKun.setVisibility(View.VISIBLE);
            ToolsKit.setImgActivity(GoodInfoActivity.this, fupincun.getF_url(), infoFuPinImg);
            infoFuPinCunZi.setText(fupincun.getName() + "");
            JSONArray jsonArray = JSONArray.parseArray(fupincun.getContext());
            JSONArray jsonArray1 = new JSONArray();
            for (Object o : jsonArray) {
                JSONObject jsonObject = (JSONObject) o;
                if (("text").equals(jsonObject.getString("type"))) {
                    jsonArray1.add(jsonObject);
                }
            }
            JSONObject params = new JSONObject();
            params.put("pageNumber", 1);
            params.put("pageSize", 10);
            if (jsonArray1.size() > 0) {
                JSONObject jsonObject = (JSONObject) jsonArray1.get(0);
                infoFuPinContent.setText(jsonObject.get("text") + "");
            }
            infoFuPinXaingQing.setOnClickListener(v -> {
                Bundle bundle = new Bundle();
                bundle.putInt("fupincunId", fupincun.getFupincun_id());
                ToolsKit.goDh(this, FpCunInfoActivity.class, bundle);
            });
        }
    }

    //设置标签
    private void setLable(GoodInfoEntity goodInfoEntity) {
        LogKit.E("aaaa ---->   ", "  " + goodInfoEntity.getG_labels());
        JSONArray lables = JSONArray.parseArray(goodInfoEntity.getG_labels());
        if (lables != null) {
            JSONArray jsonArray = new JSONArray();
            for (Object o : lables) {
                JSONObject jsonObject = (JSONObject) o;
                if (jsonObject.getBoolean("active")) {
                    jsonArray.add(o);
                }
            }
            if (jsonArray.size() > 0) {
                lableLl.setVisibility(View.VISIBLE);
                lableFlowLayout.setVisibility(View.VISIBLE);
                ToolsKit.addMarginDp(ysGuiGe, 0, 10, 0, 0);
                lableFlowLayout.setAdapter(new TagAdapter<Object>(jsonArray) {
                    @Override
                    public View getView(FlowLayout parent, int position, Object zuiJinEntity) {
                        JSONObject jsonObject = (JSONObject) zuiJinEntity;
                        String name = jsonObject.getString("name");
                        View inflate = getLayoutInflater().inflate(R.layout.good_info_lable_item, lableFlowLayout, false);
                        TextView viewById = inflate.findViewById(R.id.biao_qian);
                        viewById.setText(name + "");
                        return inflate;
                    }
                });
                lableFlowLayout.setOnTagClickListener((view, position, parent) -> {
                    TagView tagView = (TagView) view;
                    tagView.setChecked(false);
                    return true;
                });
            }
        }
    }

    //设置规格信息
    private void setGuiGe(GoodInfoEntity goodInfoEntity) {
        if (goodInfoGuiGeEntity == null) {
            ToolsKit.setText(infoFuiGeYiXuan, "请选择规格");
            ToolsKit.setText(infoFuiGeName, "");
        } else {
            ToolsKit.setText(infoFuiGeYiXuan, "已选");
            ToolsKit.setText(infoFuiGeName, goodInfoGuiGeEntity.getNow_gui_ge_name());
        }
    }

    //商品列表图片
    private void setImages(GoodInfoEntity goodInfoEntity) {
        List<String> images = new ArrayList<>();
        List<GoodInfoEntity.DetailGoodsImgsBean> detailGoodsImgs = goodInfoEntity.getDetailGoodsImgs();
        for (GoodInfoEntity.DetailGoodsImgsBean img : detailGoodsImgs) {
            images.add(img.getF_url());
        }
        infoRecycle.setLayoutManager(new LinearLayoutManager(this));
        infoRecycle.setAdapter(new BaseQuickAdapter<String, BaseViewHolder>(R.layout.good_info_view, images) {
            @Override
            protected void convert(BaseViewHolder helper, String item) {
                ToolsKit.setImgListRecycler(GoodInfoActivity.this,
                        item, helper.getView(R.id.good_list_image));
            }
        });

    }

    //最下方复制信息
    private void setWeiXin() {
        infoWeiXinCopy.setOnClickListener(v -> {
            boolean b = ToolsKit.copyText("阿凡优选");
            if (b) {
                ToastUtils.showShort("已复制到剪切板");
            }
        });

    }

    //设置商品描述
    private void setContent(GoodInfoEntity goodInfoEntity) {
        infoXianJia.setText("￥" + goodInfoEntity.getGoodsPrice().getGoods_price() + "");
        infoYuanJia.setText("￥" + goodInfoEntity.getGoodsPrice().getGoods_origin_price() + "");
        ToolsKit.setTextDelete(infoYuanJia);
        infoGoodTitle.setText(goodInfoEntity.getG_name());
        infoGoodContent.setText(goodInfoEntity.getG_introduction());
    }

    //设置Banner
    private void setBanner(GoodInfoEntity goodInfoEntity) {
        List<String> images = new ArrayList<>();
        List<GoodInfoEntity.GoodsImgsBean> goodsImgs = goodInfoEntity.getGoodsImgs();
        for (GoodInfoEntity.GoodsImgsBean imgs : goodsImgs) {
            images.add(imgs.getF_url());
        }

        goodInfoBanner.setPages(new HolderCreator(), images)
                .setPageIndicator(new int[]{R.drawable.good_info_no_fouces, R.drawable.good_info_yes_fouces})
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .setPageTransformer(new AccordionTransformer())
                .startTurning(3000)
                .setCanLoop(true);

//        DefaultTransformer
//        AccordionTransformer
//        BackgroundToForegroundTransformer
//        CubeInTransformer
//        CubeOutTransformer
//        DepthPageTransformer
//        FlipHorizontalTransformer
//        FlipVerticalTransformer
//        ForegroundToBackgroundTransformer
//        RotateDownTransformer
//        RotateUpTransformer
//        StackTransformer
//        ZoomInTransformer
//        ZoomOutTranformer
//        transformerArrayAdapter.notifyDataSetChanged();
    }

    //添加购物车
    private void insertCart() {
        JSONObject para = new JSONObject();
        para.put("goodsPriceId", goodInfoGuiGeEntity.getNow_gui_ge());
        para.put("goodsCount", goodInfoGuiGeEntity.getNow_count());
        new OkHttpKit().send(
                response200 -> {
                    JSONObject jsonObject = JSONObject.parseObject(response200);
                    if (jsonObject.getBoolean("success")) {
                        ToastUtils.showShort("添加购物车完成");
                    } else {
                        ToastUtils.showShort("添加购物车失败");
                    }
                },
                success401 -> {
                    ToastUtils.showShort("登陆后使用");
                },
                error -> {
                    ToastUtils.showShort("登录失效，请重新登录");
                }
        ).post(CONST.CART_INSERT + UserKit.getAccessToken(), para, this);
    }

    //直接下单
    private void downOrder() {
        LogKit.E("前往支付。。。。   ", " 前往支付。。。。 ");
//        Bundle bundle = new Bundle();
//        bundle.putString("now_name", goodInfoGuiGeEntity.getNow_name());
//        bundle.putDouble("now_price", goodInfoGuiGeEntity.getNow_price());
//        bundle.putDouble("now_origin_price", goodInfoGuiGeEntity.getNow_origin_price());
//        bundle.putString("now_gui_ge", goodInfoGuiGeEntity.getNow_gui_ge());
//        bundle.putInt("now_price_id", goodInfoGuiGeEntity.getNow_price_id());
//        bundle.putString("now_gui_ge_name", goodInfoGuiGeEntity.getNow_gui_ge_name());
//        bundle.putString("now_good_id", goodInfoGuiGeEntity.getNow_good_id() + "");
//        bundle.putInt("now_count", goodInfoGuiGeEntity.getNow_count());
//        bundle.putString("now_img_url", goodInfoGuiGeEntity.getNow_img_url());
//        bundle.putString("now_type", CONST.ORDER_TYPE_NOW_BY);
//        ToolsKit.goDh(this, OrderDownActivity.class, bundle);
    }

    //各种监听
    private void addLinster(GoodInfoEntity goodInfoEntity) {
        /*** 分享**/
//            ToolsKit.openShareBottom(this);
        /*** 收藏**/
        googInfoBottomShouc.setOnClickListener(v -> {
            ToolsKit.setSleep(googInfoBottomShouc, 1000);
            ToolsKit.goDh(this, KeFuActivity.class);
        });
        /*** 跳转购物车**/
        googInfoBottomCart.setOnClickListener(v -> {
            ToolsKit.setSleep(googInfoBottomCart, 1000);
            ToolsKit.goDh(this, ShopCartActivity.class);
        });
        /*** 添加购物车**/
        googInfoBottomJia.setOnClickListener(v -> {
            ToolsKit.setSleep(googInfoBottomJia, 1000);
            if (goodInfoGuiGeEntity == null) {
                ToolsKit.openGuiGeTrue(this, goodInfoEntity.getId(), CONST.OPEN_INSERT_CART);
            } else {
                insertCart();
            }
        });
        /*** 立即购买**/
        googInfoBottomBy.setOnClickListener(v -> {
            ToolsKit.setSleep(googInfoBottomBy, 1000);
            if (goodInfoGuiGeEntity == null) {
                ToolsKit.openGuiGeTrue(this, goodInfoEntity.getId(), CONST.OPEN_NOW_BY);
            } else {
                downOrder();
            }
        });
        /*** 选择规格**/
        ysGuiGe.setOnClickListener(v -> {
            ToolsKit.setSleep(ysGuiGe, 1000);
            ToolsKit.openGuiGeTrue(this, goodInfoEntity.getId(),
                    CONST.OPEN_SELECT_GUI_GE, responseGuiGe -> {
                        LogKit.E(" para  ", "  " + responseGuiGe);
                        goodInfoGuiGeEntity = JSONObject.parseObject(responseGuiGe.toJSONString(), GoodInfoGuiGeEntity.class);
                        infoFuiGeYiXuan.setText("已选");
                        infoFuiGeName.setText(goodInfoGuiGeEntity.getNow_gui_ge_name() + "");
                        infoXianJia.setText("￥" + goodInfoGuiGeEntity.getNow_price() + "");
                        infoYuanJia.setText("￥" + goodInfoGuiGeEntity.getNow_origin_price() + "");
                    });
        });
        /*** 跳转追溯**/
        infoSuYuan.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putString("url", "http://ptp.ccbz.org.cn/?traceability_code="
                    + goodInfoEntity.getG_trace_code() + "&onOff=0");
            bundle.putString("title", "追溯平台");
            ToolsKit.goDh(this, WebViewActivity.class, bundle);
        });
        /*** 查看商品评价**/
        lookPjAll.setOnClickListener(v -> {

        });
        /*** 查看全部评价**/
        pjAll.setOnClickListener(v -> {

        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());
        ButterKnife.bind(this);
        StatusBarKit.immersiveBlackTitleText(this); //设置当前activity为沉浸
        Bundle extras = this.getIntent().getExtras();
        /*** 获取商品ID**/
        if (extras != null) {
            id = extras.getInt("id");
            initData();
        } else {
            ToastUtils.showShort("数据异常");
            finish();
            overridePendingTransition(R.anim.slide_left_out, R.anim.slide_right_in);
        }
    }

    //    /*** 取消收藏**/
    private void delShouCang(int id) {
        String url = CONST.HTTP + CONST.DELETE_FAVORITES + UserKit.getAccessToken();
        JSONObject para = new JSONObject();
        ArrayList<Object> objects = new ArrayList<>();
        objects.add(id);
        para.put("goodsIds", objects);


        new OkHttpKit().send(
                response200 -> {
                    JSONObject jsonObject = JSONObject.parseObject(response200);
                    if (jsonObject.getBoolean("success")) {
                        ToastUtils.showShort("已取消收藏");
                        ToolsKit.setBackImg(R.mipmap.collection, googInfoBottomXin);
                    } else {
                        ToastUtils.showShort("取消收藏失败");
                        ToolsKit.setBackImg(R.mipmap.collection_ov, googInfoBottomXin);
                    }
                },
                success401 -> {
                    ToastUtils.showShort("取消收藏失败");
                },
                error -> {
                    ToastUtils.showShort("取消收藏失败");
                }
        ).post(CONST.DELETE_FAVORITES + UserKit.getAccessToken(), para, this);
    }

    //    /*** 添加收藏**/
    private void addShouCang(int id) {
        String url = CONST.HTTP + CONST.SAVE_FAVORITES + UserKit.getAccessToken();
        JSONObject para = new JSONObject();
        para.put("goodsId", id + "");

        new OkHttpKit().send(
                response200 -> {
                    JSONObject jsonObject = JSONObject.parseObject(response200);
                    if (jsonObject.getBoolean("success")) {
                        ToastUtils.showShort("收藏成功");
                        ToolsKit.setBackImg(R.mipmap.collection_ov, googInfoBottomXin);
                    } else {
                        ToastUtils.showShort("收藏失败");
                        ToolsKit.setBackImg(R.mipmap.collection, googInfoBottomXin);
                    }
                },
                success401 -> {
                    ToastUtils.showShort("收藏失败");
                },
                error -> {
                    ToastUtils.showShort("收藏失败");
                }
        ).post(CONST.SAVE_FAVORITES + UserKit.getAccessToken(), para, this);
    }

    @Override
    public void onDestroy() {
//        ToolsKit.clearImgActivity(GoodInfoActivity.this, infoRecycle);
        ToolsKit.deleteOKHttp(this);
        LogKit.E("deleteOKHttp ---->   ", "  deleteOKHttp");
        super.onDestroy();

    }

    @Override
    public void onBackPressed() {
        finish();
        ToolsKit.goCloseDh(this);
    }
}